<template>
  <Modal title="增加"
         v-model="modelView"
         :mask-closable="false"
         :fullscreen="false"
         :width="800"
         :closable="false"
         @on-visible-change="changeVisible"
         @on-ok="ok">
    <Form :model="formData" :label-width="80">
      <Row :gutter="16">
        <Col :span="11">
          <FormItem label="报表参数:">
            <Input v-model="formData.reportParam"/>
          </FormItem>
        </Col>
        <Col :span="11">
          <FormItem label="参数名称:">
            <Input v-model="formData.paramName"/>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="16">
        <Col :span="11">
          <FormItem label="参数类型:">
            <Input v-model="formData.paramType"/>
          </FormItem>
        </Col>
      </Row>
    </Form>
    <div slot="footer">
      <Button type="text" @click="cancel">取消</Button>
      <Button type="primary" :loading="buttonLoading" @click="ok">确定</Button>
    </div>
  </Modal>

</template>

<script>
  export default {
    name: "addParam",
    props: {
      visible: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        modelView: false,
        formData: {
          reportParam: null,
          paramName: null,
          paramType: null
        },
        buttonLoading: false
      }
    },
    watch: {
      visible(newVal) {
        this.modelView = newVal
      }
    },
    methods: {
      changeVisible() {
        this.formData = {}
        this.$emit('update:visible', this.modelView)
      },
      cancel() {
        this.modelView = false
      },
      ok() {
        const self = this
        self.buttonLoading = true
        let newData = JSON.parse(JSON.stringify(self.formData))
        setTimeout(() => {
          self.buttonLoading = false
          self.modelView = false
          self.$emit('on-ok', newData)
        }, 100);
      }
    }
  }
</script>

<style scoped>

</style>
